per chi vuole provare a simulare le cose in tempo reale
qr code che manda a questo link https://github.com/sitalaura/link-functions/tree/main/R
oppure scaricare il file a questo percorso sitalaura.github.io/link-functions/R/datasim.R
independent variable: age in years (years)
dependent variable: mistakes in a reading task (errors)
aggiungi screenshot dataset
using the classical linear predictor
using the appropriate distribution family=poisson
but, most importantly, the appropriate link link="log"
independent variable: age in years (years)
dependent variable: mistakes in a reading task (errors)
adding a new main effect
groups: normal kids (group = 0) vs kids with dyslexia (group = 1)
an interaction would emerge with a classical linear model (commenta l’output)
fitL_0 = glmmTMB(y ~ age + group + (1|id), data=d)
fitL_1 = glmmTMB(y ~ age * group + (1|id), data=d)
anova(fitL_0, fitL_1)Data: d
Models:
fitL_0: y ~ age + group + (1 | id), zi=~0, disp=~1
fitL_1: y ~ age * group + (1 | id), zi=~0, disp=~1
Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
fitL_0 5
fitL_1 6 1320.3 1341.5 -654.17 1308.3 1
no interaction !
fitP_0 = glmmTMB(y ~ age + group + (1|id), family=poisson(link="log"), data=d)
fitP_1 = glmmTMB(y ~ age * group + (1|id), family=poisson(link="log"), data=d)
anova(fitP_0, fitP_1)Data: d
Models:
fitP_0: y ~ age + group + (1 | id), zi=~0, disp=~1
fitP_1: y ~ age * group + (1 | id), zi=~0, disp=~1
Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
fitP_0 4 1210.6 1224.7 -601.31 1202.6
fitP_1 5 1212.5 1230.1 -601.25 1202.5 0.116 1 0.7334
type I error arriva da 0.05 a 50% sulle interazioni con la link function sbagliata show code (da fare) grafico
conclusioni
All materials are available on GitHub at sitalaura/link-functions
Questions and feedbacks laura.sita@studenti.unipd.it
if we put the wrong family, but the correct link family=gaussian(link="log") still no interaction (as it should)
fitL_log_0 <- glmmTMB(y ~ age + group + (1|id), family = gaussian(link="log"), data=d, start=list(beta=c(b0, 0, 0)))
fitL_log_1 <- glmmTMB(y ~ age * group + (1|id), family = gaussian(link="log"), data=d, start=list(beta=c(b0, 0, 0, 0)))
anova(fitL_log_0, fitL_log_1)Data: d
Models:
fitL_log_0: y ~ age + group + (1 | id), zi=~0, disp=~1
fitL_log_1: y ~ age * group + (1 | id), zi=~0, disp=~1
Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
fitL_log_0 5 1228.8 1246.4 -609.41 1218.8
fitL_log_1 6 1230.3 1251.5 -609.16 1218.3 0.4946 1 0.4819
Cognitive Science Arena 2026